from likeshop_api_project.api.login_api import login_model
from likeshop_api_project.base.mybase import Tools


# 结算详情/提交订单
class settle_model(Tools):
    path = '/api/order/buy'

    def settle_action(self, pay_way, goodlist, remark, action, type, address_id, use_integral, hd):
        settle_data = {
                "pay_way": pay_way,
                "goods": goodlist,
                "remark": remark,
                "action": action,
                "type": type,
                "address_id": address_id,
                "use_integral": use_integral
        }
        print(settle_data)
        settle = self.huihua.post(url=self.hosturl+self.path, json=settle_data, headers=hd)
        return settle.json()



if __name__ == '__main__':
    import requests

    s = requests.session()
    reg = login_model(huihua=s)
    msg = reg.login_action(account="13356786546", password="rr98765", client=2)
    # print(msg)
    get_token = msg["data"]["token"]
    # print(get_token)
    hd = {"token": get_token}

    settle = settle_model(huihua=s)
    msg = settle.settle_action(pay_way=3, goodlist=[{"item_id": 6, "num": 1}], remark='', action="submit",
                               type="buy_now",
                               address_id=831, use_integral=1, hd=hd)
    print(msg)
